﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Agency_updateproduct : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            if (!IsPostBack)
            {
                InitPage();
                Db db = new Db();
                

                string strSelecompany = "select companyName_sc,usercode_sc from SupplyPlan_Goods where productid='"+SysFun.IsSQL(Request.QueryString["productid"])+"'";
                DataTable dt = db.DataTable(strSelecompany);
                db.Close();
                if (dt.Rows.Count > 0)
                {
                    this.DataList1.DataSource = dt;
                    this.DataList1.DataBind();
                }
                else
                {
                    this.DataList1.Visible = false;
                }
                dt = null;
                db.Close();
                db = null;
            }

        }
       

    }
    private void InitPage()
    {
        Db db=new Db();
        string strsql = "select productid,ProductName,Medicinemodel,Outlookc,Unit from product where productid='" + SysFun.IsSQL(Request.QueryString["productid"]) + "'";
        System.Data.IDataReader dr = db.DataReader(strsql);
        while (dr.Read())
        {
            this.ProductName.Text = dr["ProductName"].ToString();
            this.Medicinemodel.Text = dr["Medicinemodel"].ToString();
            this.Outlookc.Text = dr["Outlookc"].ToString();
            this.Unit.Text = dr["Unit"].ToString();
        }
        dr.Close();
        db.Close();
        dr = null;
        db = null;
        

    }
    protected void butSave_Click(object sender, EventArgs e)
    {
        
        string insertsql="";
        Db db = new Db();
        string strsql = "select SpellingCode,productid,ProductName,Medicinemodel,Outlookc,Unit from product where productid='" + SysFun.IsSQL(Request.QueryString["productid"]) + "'";
        System.Data.IDataReader dr = db.DataReader(strsql);
        while (dr.Read())
        {

            string sql=HZ.MBSM.BLL.PYM.GetChineseSpell(dr["ProductName"].ToString());
            //string stsql=HZ.MBSM.BLL.PYM.GetChineseSpell(this.ProductName.Text.ToString());
            if (this.ProductName.Text == dr["ProductName"].ToString() & this.Medicinemodel.Text == dr["Medicinemodel"].ToString() & this.Outlookc.Text == dr["Outlookc"].ToString() & this.Unit.Text == dr["Unit"].ToString())
            {
                Response.Write("<script>alert('还没修改')</script>");
            }
            
            else
            {
               // insertsql += "@" + "insert backupproduct(productid,ProductName,Medicinemodel,Outlookc,Unit,SpellingCode) values('" + Request.QueryString["productid"] + "','" + dr["ProductName"] + "','" + dr["Medicinemodel"] + "','" + dr["Outlookc"] + "','" + dr["Unit"] + "','"+sql+"')";
                insertsql += "@" + "update backupproduct set ProductName='" + this.ProductName.Text + "',SpellingCode='" + sql + "',Medicinemodel='" + this.Medicinemodel.Text + "',Outlookc='" + this.Outlookc.Text + "',Unit='" + this.Unit.Text + "' where productid='" + Request.QueryString["productid"] + "'";
                insertsql += "@" + "update SupplyPlan_Goods set ProductName='" + this.ProductName.Text + "',Medicinemodel='" + this.Medicinemodel.Text + "',Outlookc='" + this.Outlookc.Text + "',Unit='" + this.Unit.Text + "' where productid='" + Request.QueryString["productid"] + "'";

                
            }
        }
        dr.Close();
        dr.Dispose();
        if (insertsql != "")
        {
            db.ExecuteTransaction(insertsql.Substring(1).Split(new char[] { '@' }), 30);
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "插入", "backupproduct", insertsql, "../Agency/updateproduct.aspx");
                    
           Response.Write("<script>alert('修改成功')</script>");
        }
        
        db.Close();
        dr = null;
        db = null;

        
    }
}
